const defaultOptions = {
    title: '',
    message: '',
    cancelText: '取消',
    cancelColor: '#84878F',
    showCancel: false,
    confirmText: '确定',
    confirmColor: '#F7931E',
};
const formatOptions = (o) => {
    const opt = { ...defaultOptions };
    if (typeof o === 'string') {
        o = Object.assign(opt, { message: o });
    }
    else {
        o = Object.assign(opt, o);
    }
    return {
        title: o.title,
        content: o.message,
        showCancel: o.showCancel,
        cancelText: o.cancelText,
        cancelColor: o.cancelColor,
        confirmText: o.confirmText,
        confirmColor: o.confirmColor,
    };
};
export const dialog = (options, showCancel = false) => {
    return new Promise((resolve, reject) => {
        uni.showModal({
            ...formatOptions(options),
            showCancel,
            success: ({ confirm }) => {
                confirm ? resolve('confirm') : reject('cancel');
            },
            fail: (e) => {
                console.info('showModal fail:', e);
            },
        });
    });
};
dialog.confirm = (options) => {
    return dialog(options, true);
};
